﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * Builds Files for the exercise.
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileSystem.Impl
{
    class DataBuilder
    {
	    private static DataBuilder instance;
	
	    private DataBuilder() {
		    //intentionally empty
	    }
	
	    public static DataBuilder getInstance() {
		    if (null == instance) {
			    instance = new DataBuilder();
		    }
		    return instance;
	    }
	
	    public NodeMetaData getMetaDataForStartingFile(String name) {
		    if ("hello".Equals(name)) 		return getMetaDataForFileHello();
		    if ("dickens".Equals(name)) 	return getMetaDataForFileDickens();
		    if ("alexander".Equals(name))	return getMetaDataForFileAlexander();
		    return null;
	    }
	
	
	    public String getContentsForStartingFile(String name) {
		    if ("hello".Equals(name)) 		return getContentsForFileHello();
		    if ("dickens".Equals(name)) 	return getContentsForFileDickens();
		    if ("alexander".Equals(name))	return getContentsForFileAlexander();
		    return null;
	    }

	    public NodeMetaData getMetaDataForFileHello() {
		    String id = getNextNodeId();
		    String name = "hello";
		    DateTime creation = DateTime.Now; //now
		    int size = hello().Length;
		    return new NodeMetaData(id, name, size, creation);
	    }
	
	    public String getContentsForFileHello() {
		    return hello();
	    }
	

	    public NodeMetaData getMetaDataForFileDickens() {
		    String id = getNextNodeId();
		    String name = "dickens";
		    DateTime creation = DateTime.Now; //now
		    int size = dickens().Length;
		    return new NodeMetaData(id, name, size, creation);
	    }
	
	    public String getContentsForFileDickens() {
		    return dickens();
	    }

	    public NodeMetaData getMetaDataForFileAlexander() {
		    String id = getNextNodeId();
		    String name = "alexander";
		    DateTime creation = DateTime.Now; //now
            int size = alexander().Length;
		    return new NodeMetaData(id, name, size, creation);
	    }
	
	    public String getContentsForFileAlexander() {
		    return alexander();
	    }
	
	    private String getNextNodeId() {
            return AppResources.getInstance().getFileSystem().getNextNodeId();
        }

	    private String hello() {
		    StringBuilder rc = new StringBuilder();
		    rc.Append("Hello, World!\n");
		    return rc.ToString();		
	    }
	
	    private String dickens() {
		    StringBuilder rc = new StringBuilder();
		    rc.Append("It was the best of times, it was the worst of times;\n");
            rc.Append("It was the age of wisdom, it was the age of foolishness;\n");
            rc.Append("It was the epoch of belief, it was the epoch of incredulity;\n");
            rc.Append("It was the season of Light, it was the season of Darkness;\n");
            rc.Append("It was the spring of hope, it was the winter of despair;\n");
            rc.Append("We had everything before us, we had nothing before us;\n");
            rc.Append("We were all going direct to Heaven, we were all going direct the other way.\n");
            rc.Append("In short, the period was so far like the present period,\n");
            rc.Append("that some of its noisiest authorities insisted on its being received,\n");
            rc.Append("for good or for evil, in the superlative degree of comparison only.\n");
		    return rc.ToString();
	    }
	
	    private String alexander() {
		    StringBuilder rc = new StringBuilder();
		    rc.Append("I could not have blamed you for being the first to lose heart if I,\n");
		    rc.Append("your commander, had not shared in your exhausting marches and your perilous campaigns;\n");
		    rc.Append("it would have been natural enough if you had done all the work merely for others to reap the reward.\n");
		    rc.Append("But it is not so. You and I, gentlemen, have shared the labour and shared the danger,\n");
		    rc.Append("and the rewards are for us all. The conquered territory belongs to you;\n");
		    rc.Append("from your ranks the governors of it are chosen;\n");
		    rc.Append("already the greater part of its treasure passes into your hands,\n");
		    rc.Append("and when all Asia is overrun, then indeed I will go further than\n");
		    rc.Append("the mere satisfaction of our ambitions:\n");
		    rc.Append("the utmost hopes of riches or power which each one of you cherishes will be far surpassed,\n");
		    rc.Append("and whoever wishes to return home will be allowed to go,\n");
		    rc.Append("either with me or without me.\n");
		    rc.Append("I will make those who stay the envy of those who return.\n");
		    return rc.ToString();
	    }
    }
}
